import request from '@/utils/request'

/**
 *
 * @param {string} roleName 搜索关键字
 * @returns
 */
export const getRoleList = (page = 1, limit = 10, roleName = '') =>
  request({
    url: `/admin/acl/role/${page}/${limit}`,
    method: 'get',
    params: { roleName }
  })

// 添加角色
export const addOrupdataRoleInfo = (data) =>
  request({
    url: data.id ? '/admin/acl/role/update' : '/admin/acl/role/save',
    method: data.id ? 'put' : 'post',
    data
  })

// 删除角色
export const delRoleInfo = (id) =>
  request({ url: `/admin/acl/role/remove/${id}`, method: 'delete' })

//批量删除角色
export const batchDelRole = (idList) =>
  request({
    url: `/admin/acl/role/batchRemove`,
    method: 'delete',
    data: idList
  })

// 获取角色所对应的权限列表
export const getRoleJurisdiction = (id) =>
  request({ url: `/admin/acl/permission/toAssign/${id}`, method: 'get' })

// 修改角色权限
export const updateRoleAuth = (roleId, authids) => {
  let permissionId = authids.join(',')
  return request({
    url: `/admin/acl/permission/doAssign`,
    method: 'post',
    params: { roleId, permissionId }
  })
}
